package com.example.x.dnuifood_929dx.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.x.dnuifood_929dx.R;
import com.example.x.dnuifood_929dx.adapter.CollectAdapter;
import com.example.x.dnuifood_929dx.bean.GetCollected;
import com.example.x.dnuifood_929dx.listener.onRetrofitListener;
import com.example.x.dnuifood_929dx.model.UserModel;

import java.util.List;

/**
 * Created by X on 2018/11/27.
 */

public class CollectFoodFragment extends BaseFragment implements onRetrofitListener<List<GetCollected>> {
    private RecyclerView collect_rv;
    private CollectAdapter adapter;
    private UserModel userModel;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        
        setLayout_file(R.layout.collectfoodfragment);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    void initViews() {
        collect_rv = (RecyclerView)view.findViewById(R.id.rv);
        collect_rv.setLayoutManager(new LinearLayoutManager(getActivity()));
        collect_rv.setHasFixedSize(true);
    }

    @Override
    void initEvents() {

    }

    @Override
    void initData() {
        userModel=new UserModel();
        userModel.getAllUserCollection(getUser_id(),"1",this);
    }





    @Override
    public void onSuccess(List<GetCollected> object, int flag) {
        adapter=new CollectAdapter(context, object,R.layout.shop_item4);
        collect_rv.setAdapter(adapter);
    }

    @Override
    public void onFailure(String msg) {
        Toast.makeText(context, "失败："+msg, Toast.LENGTH_SHORT).show();
    }
}
